// import com.alibaba.druid.DbType;
// import com.alibaba.druid.sql.ast.SQLExpr_ptr;
// import com.alibaba.druid.sql.ast.SQLObject;
// import com.alibaba.druid.sql.visitor.SQLASTVisitor;

// import java.util.ArrayList;
// import java.util.List;

#include "SQLGrantStatement.h"
#include "../../visitor/SQLASTVisitor.h"
#include "../../../utils/listTran.h"
#include "SQLPrivilegeItem.h"

SQLGrantStatement::SQLGrantStatement()
{
}

SQLGrantStatement::SQLGrantStatement(DbType_ptr dbType)
  :SQLPrivilegeStatement(dbType)
{
}

// @Override
void SQLGrantStatement::accept0(SQLASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(SQLGrantStatement)))
  {
    SQLObject_list_ptr tmp1 = ListTran::tran_class<SQLPrivilegeItem, SQLObject>(this->privileges);
    acceptChild(visitor, tmp1);
    acceptChild(visitor, resource);
    SQLObject_list_ptr tmp2 = ListTran::tran_class<SQLExpr, SQLObject>(users);
    acceptChild(visitor, tmp2);
    acceptChild(visitor, identifiedBy);
  }
  visitor->endVisit(SharedObject(SQLGrantStatement));
}

// @Override
SQLObject_list_ptr SQLGrantStatement::getChildren()
{
  SQLObject_list_ptr children = std::make_shared<std::list<SQLObject_ptr>>();
  // children.addAll(privileges);
  for (auto it : *privileges)
  {
    children->push_back(std::dynamic_pointer_cast<SQLObject>(it));
  }
  if (resource != nullptr)
  {
    children->push_back(resource);
  }
  if (users != nullptr)
  {
    // children.addAll(users);
    for (auto it : *users)
    {
      children->push_back(std::dynamic_pointer_cast<SQLObject>(it));
    }
  }
  if (identifiedBy != nullptr)
  {
    children->push_back(identifiedBy);
  }
  return children;
}

SQLObjectType_ptr SQLGrantStatement::getResourceType()
{
  return resourceType;
}

void SQLGrantStatement::setResourceType(SQLObjectType_ptr resourceType)
{
  this->resourceType = resourceType;
}

SQLExpr_ptr SQLGrantStatement::getMaxQueriesPerHour()
{
  return maxQueriesPerHour;
}

void SQLGrantStatement::setMaxQueriesPerHour(SQLExpr_ptr maxQueriesPerHour)
{
  this->maxQueriesPerHour = maxQueriesPerHour;
}

SQLExpr_ptr SQLGrantStatement::getMaxUpdatesPerHour()
{
  return maxUpdatesPerHour;
}

void SQLGrantStatement::setMaxUpdatesPerHour(SQLExpr_ptr maxUpdatesPerHour)
{
  this->maxUpdatesPerHour = maxUpdatesPerHour;
}

SQLExpr_ptr SQLGrantStatement::getMaxConnectionsPerHour()
{
  return maxConnectionsPerHour;
}

void SQLGrantStatement::setMaxConnectionsPerHour(SQLExpr_ptr maxConnectionsPerHour)
{
  this->maxConnectionsPerHour = maxConnectionsPerHour;
}

SQLExpr_ptr SQLGrantStatement::getMaxUserConnections()
{
  return maxUserConnections;
}

void SQLGrantStatement::setMaxUserConnections(SQLExpr_ptr maxUserConnections)
{
  this->maxUserConnections = maxUserConnections;
}

BOOL_ptr SQLGrantStatement::isAdminOption()
{
  return adminOption;
}

void SQLGrantStatement::setAdminOption(BOOL_ptr adminOption)
{
  this->adminOption = adminOption;
}

SQLExpr_ptr SQLGrantStatement::getIdentifiedBy()
{
  return identifiedBy;
}

void SQLGrantStatement::setIdentifiedBy(SQLExpr_ptr identifiedBy)
{
  this->identifiedBy = identifiedBy;
}

string_ptr SQLGrantStatement::getIdentifiedByPassword()
{
  return identifiedByPassword;
}

void SQLGrantStatement::setIdentifiedByPassword(string_ptr identifiedByPassword)
{
  this->identifiedByPassword = identifiedByPassword;
}

BOOL_ptr SQLGrantStatement::getWithGrantOption()
{
  return withGrantOption;
}

void SQLGrantStatement::setWithGrantOption(BOOL_ptr withGrantOption)
{
  this->withGrantOption = withGrantOption;
}
